package objects
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author Ja
	 */
	public class Squere extends Sprite
	{
		
		
		public var vx:Number=0;
		public var vy:Number=0;
		public var bounce:Number = -0.7;
		public var gravity:Number = 10;
		public var mass:Number = 1;
		
		
		public var easing:Number = .2;
		public var spring:Number = .1;
		public var friction:Number = .95;
		
		public var left:Number = 0;
		public var right:Number = 0;
		public var top:Number = 0;
		public var bottom:Number = 0;
		
		public var dragging:Boolean = false;
		
		public var oldX:Number;
		public var oldY:Number;
		
		public var dx:Number;
		public var dy:Number;
		
		public var ax:Number;
		public var ay:Number;
		
		public var target:Point = new Point();;
		
		private var addEye:Boolean=false;
		public var radius:Number;
		public function Squere(w:Number = 40,h:Number = 40, color:uint = 0xff0000, center:Boolean=false, a:Number = .5, stroke:Boolean = true, aa:Number = .8)
		{
			
			
			if (stroke)graphics.lineStyle(1,0xffffff,aa);
			graphics.beginFill(color, a);
			if (center) graphics.drawRect( -w / 2, -h / 2, w, h);
			else graphics.drawRect( 0, 0, w, h);
			graphics.endFill();
			
			
			//x = width >> 1;
			//y = height >> 1;
			
			addEventListener(Event.ADDED_TO_STAGE, onAdded)
		}
		
		private function onAdded(e:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, onAdded);
			
			oldX = x;
			oldY = y;
			
			
			
			
			
			left = 0+width/2;
			right = stage.stageWidth-this.width/2;
			top = 0+this.height/2;
			bottom = stage.stageHeight - this.height / 2;
			
		}
		
		public function trackVelocity():void
		{
			vx = x - oldX;
			vy = y - oldY;
			oldX = x;
			oldY = y;
		}
		
		public function addEasing(target:Point = null, easing:Number = .2):void
		{
			if (!target) {
				target = new Point(Math.random() * stage.stageWidth, Math.random() * stage.stageHeight);
			}
			this.target = target;
			this.easing = easing;
			vx = (this.target.x - x) *this.easing;
			vy = (this.target.y - y) *this.easing;
		}
		
		
	
	}

}